<script>

	import {
		shareList,
		systemConfig
	} from "@/api/public.js"
	export default {
		globalData: {
			//#ifdef MP-WEIXIN
			MenuButtonTop: 0,
			MenuButtonBottom: 0,
			//#endif

		},
		onShow: function() {
			// 小程序版本更新
			// #ifdef MP-WEIXIN
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {
				// 请求完新版本信息的回调
				if (res.hasUpdate) {
					updateManager.onUpdateReady(function(res) {
						uni.showModal({
							title: '更新提示',
							content: '新版本已经准备好，是否重启应用？',
							success(res) {
								if (res.confirm) {
									// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
									updateManager.applyUpdate();
								}
							}
						});
					});
					updateManager.onUpdateFailed((res) => {
						// 新的版本下载失败
						uni.showModal({
							content: '新版本下载失败，请您删除当前小程序，重新搜索打开~',
							showCancel: false
						})
					});
				}
			});
			// #endif
			// 登录过期判断
			let expires_time = uni.getStorageSync('expires_time')
			if (expires_time) {
				if (expires_time < Date.parse(new Date()) / 1000) {
					uni.clearStorageSync()
				}
			}
			// 小程序胶囊位置获取
			//#ifdef MP-WEIXIN
			this.$scope.globalData.MenuButtonTop = uni.getMenuButtonBoundingClientRect().top
			this.$scope.globalData.MenuButtonBottom = uni.getMenuButtonBoundingClientRect().bottom
			//#endif
			// 分享图片
			shareList().then(res => {
				uni.setStorageSync("share", res.data)
			})
			systemConfig({ //联系电话
				filed: 'site_phone'
			}).then(res => {
				uni.setStorageSync("servicePhone", res.msg)
			})
			systemConfig({ //客服电话
				filed: 'site_service_phone'
			}).then(res => {
				uni.setStorageSync("siteSerPhone", res.msg)
			})
			//#ifdef  APP-PLUS
			systemConfig({ //客服电话
				filed: 'is_available_ali_pay'
			}).then(res => {
				uni.setStorageSync("available_alipay", res.msg)
			})


			//#endif
			console.log('App show');
		},
		onLaunch: function() {
			//#ifdef  APP-PLUS
			let _this = this
			plus.push.addEventListener('click', function(msg) {  //监听系统通知栏消息点击事件
				console.log(msg, 222)
			}, false);
			//监听透传消息事件 
			//【APP离线】收到消息，但没有提醒（发生在一次收到多个离线消息时，只有一个有提醒，但其他的没有提醒）
			//【APP在线】收到消息，不会触发系统消息,需要创建本地消息，但不能重复创建。必须加msg.type验证去除死循环   
			plus.push.addEventListener('receive', function(msg) {
				//创建本地消息,发送的本地消息也会被receive方法接收到，但没有type属性，且aps是null
				let devlop = uni.getSystemInfoSync().platform
				if (devlop == "android") { //如果是android 
					// 创建本地消息
					plus.push.createMessage(msg.payload, msg.payload, {
						title: "国家普惠社区"
					});
					var main = plus.android.runtimeMainActivity();
					var SpeechUtility = plus.android.importClass('com.iflytek.cloud.SpeechUtility');
					var SpeechConstant = plus.android.importClass('com.iflytek.cloud.SpeechConstant');
					SpeechUtility.createUtility(main, "appid=5f86674a");
					var SynthesizerPlayer = plus.android.importClass('com.iflytek.cloud.SpeechSynthesizer');
					var play = SynthesizerPlayer.createSynthesizer(main, null);
					play.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan"); //设置发音人  
					play.setParameter(SpeechConstant.SPEED, "6"); //设置语速    
					play.setParameter(SpeechConstant.VOLUME, "100"); //设置音量，范围0~100 
					let manuf = plus.device.vendor //手机厂商信息
					if (manuf == 'Xiaomi'|| manuf == 'OPPO') {
						
						play.startSpeaking(msg.payload, null);
					} else {
						play.startSpeaking(_this.changeEnCode(msg.payload), null);
					}
				} else {
					console.log(msg, 1111222)
					var payload = msg.payload;
					if (msg.aps == null && msg.type == "receive") {
						//创建本地消息,发送的本地消息也会被receive方法接收到，但没有type属性，且aps是null  
						plus.push.createMessage(msg.payload, msg.payload, {
							title: "国家普惠社区"
						}); 
						// ios文字转语音 
						var AVAudioSession = plus.ios.importClass("AVAudioSession");
						var AVSpeechSynthesizer = plus.ios.importClass("AVSpeechSynthesizer");
						var AVSpeechUtterance = plus.ios.importClass("AVSpeechUtterance");
						var AVSpeechSynthesisVoice = plus.ios.import("AVSpeechSynthesisVoice");
						AVAudioSession.sharedInstance().setCategoryerror("AVAudioSessionCategoryPlayback", null);
						var sppech = new AVSpeechSynthesizer();
						var utterance = AVSpeechUtterance.speechUtteranceWithString(msg.payload);
						utterance.plusSetAttribute("rate", 0.4);
						sppech.speakUtterance(utterance);
					}
				}

			}, false);
			//#endif
		},
		onHide: function() {
			// console.log('App Hide');
		},
		methods: {
			changeEnCode(str) {
				let res = []
				for (let i = 0; i < str.length; i++) {
					// 这个不是正常的encodeUnicode 颠倒了大小端的位置
					res[i] = ("00" + str.charCodeAt(i).toString(16)).slice(-2) + ("00" + str.charCodeAt(i).toString(16)).slice(-4, -2)
				}
				let strCode = "\\u" + res.join("\\u")
				strCode = strCode.replace(/\\/g, "%")
				return unescape(strCode)
			}
		}
	};
</script>

<style lang="scss">
	/*
		全局公共样式和字体图标
	*/
	@font-face {
		font-family: yticon;
		font-weight: normal;
		font-style: normal;
		/* src: url('~@/static/yticon.ttf'); */
		src: url('https://at.alicdn.com/t/font_1078604_w4kpxh0rafi.ttf') format('truetype');

	}

	.yticon {
		font-family: "yticon" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}


	.icon-shang:before {
		content: "\e624";
	}

	.icon-xia:before {
		content: "\e62d";
	}

	.icon-you:before {
		content: "\e606";
	}

	.icon-zuo:before {
		content: "\e63c";
	}

	.icon-shoucang:before {
		content: "\e645";
	}

	.icon-gouwuche:before {
		content: "\e609";
	}

	.icon-xiatubiao--copy:before {
		content: "\e608";
	}

	.icon-xingxing:before {
		content: "\e70b";
	}

	.icon-bangzhu1:before {
		content: "\e63d";
	}

	.icon-fork:before {
		content: "\e61b";
	}

	.icon-xuanzhong2:before {
		content: "\e62f";
	}

	.icon-shouye:before {
		content: "\e626";
	}

	.icon-dizhi:before {
		content: "\e614";
	}

	.icon-share:before {
		content: "\e656";
	}

	.icon-pinglun-copy:before {
		content: "\e612";
	}

	.icon-shoucang_xuanzhongzhuangtai:before {
		content: "\e6a9";
	}

	.icon-shezhi1:before {
		content: "\e61d";
	}

	.icon-daifukuan:before {
		content: "\e68f";
	}

	.icon-yishouhuo:before {
		content: "\e71a";
	}

	.icon-shouhoutuikuan:before {
		content: "\e631";
	}

	.icon-lishijilu:before {
		content: "\e6b9";
	}

	.icon-iLinkapp-:before {
		content: "\e654";
	}

	.icon-iconfontweixin:before {
		content: "\e611";
	}

	.icon--jianhao:before {
		content: "\e60b";
	}

	.icon-jia2:before {
		content: "\e60a";
	}

	.bold {
		font-weight: bold;
	}

	/*下边框*/
	.b-b:after {
		position: absolute;
		z-index: 3;
		bottom: 0;
		left: 0;
		right: 0;
		height: 0;
		content: '';
		transform: scaleY(.5);
		border-bottom: 1px solid #f5f5f5;
	}

	/* 去滚动条 */
	/deep/.uni-scroll-view ::-webkit-scrollbar {
		/* 隐藏滚动条，但依旧具备可以滚动的功能 */
		display: none;
		width: 0;
		height: 0;
		color: transparent;
		background: transparent;
	}

	/deep/::-webkit-scrollbar {
		display: none;
		width: 0;
		height: 0;
		color: transparent;
		background: transparent;
	}

	/deep/.uni-load-more__text {
		font-size: 24rpx !important;
		color: #999 !important;
	}

	/* 单行省略号 */
	.clamp {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		display: block;
	}

	/* 俩行省略号 */
	.clamp2 {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	/**
	 * 公共样式
	 */
	.bottom__explan {
		font-size: 24rpx;
		position: fixed;
		bottom: 25rpx;
		left: 50%;
		width: 68%;
		margin-left: -34%;

		.cell-more {
			font-size: 20rpx;
			color: black;
			font-weight: 600;
		}
	}

	.mall__page {
		padding-bottom: 80rpx;
	}

	.zhiying__image {
		width: 70rpx !important;
		height: 28rpx !important;
		margin-right: 10rpx !important;
	}

	.mark-tips-model {
		transition-property: opacity;
		transition-duration: 0.2s;
		position: fixed;
		top: 0;
		height: 100vh;
		width: 100%;
		z-index: 9;
		background: rgba(0, 0, 0, .8);

		.box-type {
			width: 90%;
			position: fixed;
			margin-left: 5%;
			height: 48vh;
			bottom: 23vh;

			.mark {
				font-size: 36rpx;
				text-align: center;
			}

			.mark-btn {
				position: fixed;
				z-index: 99;
				width: 84%;
				height: 77rpx;
				line-height: 77rpx;
				background: rgba(87, 190, 106, 1);
				box-shadow: 0 4rpx 20 0 rgba(87, 190, 106, .4);
				border-radius: 39rpx;
				text-align: center;
				font-size: 28rpx;
				font-weight: 300;
				color: #fff;
				bottom: 26vh;
				margin: 0 3%;
			}
		}

		.box {
			width: 90%;
			position: fixed;
			bottom: 5vh;
			height: 79vh;
			margin-left: 5%;

			.mark-btn {
				position: fixed;
				z-index: 99;
				width: 84%;
				height: 77rpx;
				line-height: 77rpx;
				background: rgba(87, 190, 106, 1);
				box-shadow: 0 4rpx 20 0 rgba(87, 190, 106, .4);
				border-radius: 39rpx;
				text-align: center;
				font-size: 28rpx;
				font-weight: 300;
				color: #fff;
				bottom: 9vh;
				margin: 0 3%;
			}
		}

		.bell {
			width: 183rpx;
			height: 183rpx;
			position: relative;
			z-index: 99;
			top: -45rpx;

		}

		.back {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
		}

		text {
			font-size: 60rpx;
			color: #FDFAF9;
			text-shadow: 0 4rpx 10rpx rgba(6, 88, 21, 0.3);
			padding: 60rpx 0;
			display: block;
			position: relative;
			z-index: 99;
			text-align: center;
		}

		.mark-con {
			text-align: center;
			position: relative;
			top: 1vh;
			color: #999;
			font-size: 26rpx;
			line-height: 50rpx;
			width: 90%;
			margin: 0 auto;
			background: #fff;
			border-radius: 20rpx;
			max-height: 74vh;
		}

		.mark {
			text-align: left;
			padding: 0 30rpx;
			max-height: 45vh;
			overflow-y: scroll;
			padding-bottom: 100rpx;
			box-sizing: border-box;
		}

		.title {
			font-weight: 600;
		}

		.explan {
			text-indent: 2em;
			margin-bottom: 10rpx;
		}

	}
</style>
